    //
//  RootViewController_iPad.m
//  PokerPlus
//
//  Created by sunrui-MacBook on 11-7-27.
//  Copyright 2011 139.ME. All rights reserved.
//
#import "OpenFlowViewController.h"
#import "Menu_iPad.h"
#import "LoginViewController.h"
#import "ZaiXianHaoYou.h"
#import "ZhuoZiList.h"
#import "PaiZhuoXuanXiang.h"
#import "MiddleMenuBar.h"
#import "TeachViewController.h"
#import "Reference.h"
#import "RootViewController_iPad.h"

#import "TouXiang.h"
#import "Tournament.h"
#import "GetAward.h"
#import "AppDelegate_iPad.h"


#import "LoadingViewController_iPad.h"
#import "RoomViewController_iPad.h"

@implementation RootViewController_iPad

 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
		
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	NSLog(@"viewDid Load");
	openflow=[[OpenFlowViewController alloc]initWithFrame:CGRectMake(0, 99, 1024, 300)];
    openflow.backgroundColor=[UIColor clearColor];
    [self.view addSubview:openflow];
    [openflow setNumberOfImages:7];
    [openflow setSelectedCover:3];
    [openflow centerOnSelectedCover:NO];
    
    
	haoyou=[[ZaiXianHaoYou alloc]initWithNibName:@"ZaiXianHaoYou" bundle:nil];
	haoyou.view.frame=CGRectMake(25, 458, 181, 291);
	haoyou.view.backgroundColor=[UIColor clearColor];
	//[self.view addSubview:haoyou.view];
    
	zhuoList=[[ZhuoZiList alloc]initWithNibName:@"ZhuoZiList" bundle:nil];
    zhuoList.view.frame=CGRectMake(215, 458, 455, 291);
    zhuoList.view.backgroundColor=[UIColor clearColor];
    //[self.view addSubview:zhuoList.view];
    
	paizhuo=[[PaiZhuoXuanXiang alloc]initWithNibName:@"PaiZhuoXuanXiang" bundle:nil];
    paizhuo.view.frame=CGRectMake(680, 458, 310, 291);
    paizhuo.view.backgroundColor=[UIColor clearColor];
    //[self.view addSubview:paizhuo.view];

    
	middlebar=[[MiddleMenuBar alloc]initWithNibName:@"MiddleMenuBar" bundle:nil];
    middlebar.delegate=self;
    middlebar.view.frame=CGRectMake(0, 375, 1024, 80);
    middlebar.view.backgroundColor=[UIColor clearColor];
    //[self.view addSubview:middlebar.view];
	
    
    bottomView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)];
    bottomView.backgroundColor=[UIColor clearColor];
    [self.view addSubview:bottomView];
    [bottomView addSubview:openflow];
    [bottomView addSubview:haoyou.view];
    [bottomView addSubview:zhuoList.view];
    [bottomView addSubview:paizhuo.view];
    //[bottomView addSubview:choumadaxiao.view];
    [bottomView addSubview:middlebar.view];
    

	roomcontroller = [[RoomViewController_iPad alloc] initWithNibName:@"RoomViewController_iPad" bundle:nil];
	[self.view addSubview:roomcontroller.view];
	roomcontroller.view.alpha = 0.0f;
	[roomcontroller setTeachDelegate:self];
	
	menu=[[Menu_iPad alloc]initWithNibName:@"Menu_iPad" bundle:nil];
	[self.view addSubview:menu.view];
    menu.delegate=self;
    menu.view.frame=CGRectMake(0, -99, 1024, 99);
    [UIView beginAnimations:@"start" context:nil];
    [UIView setAnimationDuration:1.0f];    
    menu.view.frame=CGRectMake(0, 0,1024, 99);
    [UIView commitAnimations];
	
	
	loading = [[LoadingViewController_iPad alloc] initWithNibName:@"LoadingViewController_iPad" bundle:nil];
	[self.view addSubview:loading.view];
	
}

- (void)EnterBackGround{
	[self.view bringSubviewToFront:loading.view];
	[loading viewDidDisappear:YES];
	}

- (void)ConnectServer{
	
	[loading viewDidAppear:YES];
}

- (void)SetUsrInfo:(UsrInfo) ui{
	menu.currentUsr = ui;	
}

- (void)SetRoomSort:(RoomSort)rs{
	paizhuo.roomsort = rs;
}

- (void)SetRoomList:(RoomList)rl{
	zhuoList.roomlist = rl;
}

- (void)EnterRoom:(UpdateDesk)ud{
	
	[self bottomDisAppear];
	
//	[self.view insertSubview:roomcontroller.view belowSubview:menu.view];
//	roomcontroller.view.alpha = 0.0f;
	roomcontroller.btnView.center = CGPointMake(512, 200);
	roomcontroller.btnView.transform=CGAffineTransformMakeScale(0.7,0.7);
	
	[UIView beginAnimations:nil context:nil];
	[UIView setAnimationDuration:1.0f];
	//[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
	roomcontroller.btnView.transform=CGAffineTransformMakeScale(1,1);
	roomcontroller.btnView.center = CGPointMake(512, 384);
	roomcontroller.view.alpha = 1.0f;
	[UIView commitAnimations];
	
	[roomcontroller viewDidAppear:YES];
	//[roomcontroller setDeskInfo:ud];
}

- (void)RoomRefresh:(UpdateDesk)ud{
	[roomcontroller.table setDeskInfo:ud];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Overriden to allow any orientation.
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}


- (void)viewDidUnload {
    [openflow release];
    openflow = nil;
    control =nil;
    tour=nil;
    if (ref!=nil) {
        [ref release];
        ref=nil;
    }
    
    getA=nil;
    if (teach!=nil) {
        [teach release]; 
        teach=nil;
    }
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
- (CGAffineTransform)transformForOrientation {
    return CGAffineTransformIdentity;
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    if (orientation == UIInterfaceOrientationLandscapeLeft) {
        return CGAffineTransformMakeRotation(M_PI*1.5);
    } else if (orientation == UIInterfaceOrientationLandscapeRight) {
        return CGAffineTransformMakeRotation(M_PI/2);
    } else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
        return CGAffineTransformMakeRotation(-M_PI);
    } else {
        return CGAffineTransformIdentity;
    }
}
-(void)bottomDisAppear{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3];
    bottomView.transform=CGAffineTransformScale([self transformForOrientation], 1.5, 1.5);
    
    bottomView.alpha=0.0;
    [UIView commitAnimations];
}


- (void)dealloc {
    [getA release];
    
    [menu release];
    [tour release];
    [haoyou release];
    [zhuoList release];
    [paizhuo release];
    [ref release]; 
    [middlebar release];
    [openflow release];
    if (teach!=nil) {
        
        [teach release]; 
        teach=nil;
    }
    if (control!=nil) 
        [control release];
	
	[loading release];
	[roomcontroller release];
    [super dealloc];
}
#pragma mark ----MiddleMeneBarDelegate---- 
-(void)jiaoxue{
    
    [self  bottomDisAppear];
    if (teach==nil) {
        teach=[[TeachViewController alloc]init];
        teach.delegate=self;
    }
    teach.view.frame=CGRectMake(0, 0, 1024, 768);
    [self.view addSubview:teach.view];
    teach.view.alpha=0.0;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
    teach.view.alpha=1.0;
    [UIView commitAnimations];
    [teach viewWillAppear:YES];
    [self.view bringSubviewToFront:menu.view];
    
}
-(void)jinbiaosai{
    if (tour!=nil) {
        [tour.view removeFromSuperview];
        [tour release]; 
        tour=nil;
    }
    if (tour==nil) {
        tour=[[Tournament alloc]initWithNibName:@"Tournament" bundle:nil];
        tour.delegate=self;
        tour.view.frame=CGRectMake(250, 150, 522, 349);
    }
    if (control==nil) 
        control=[[UIControl alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)];
    control.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.0];
    [self.view addSubview:control];
    [control addSubview:tour.view];
    tour.view.alpha=0.0f;
    [control addTarget:self action:@selector(removeControl:) forControlEvents:UIControlEventTouchUpInside];
    [UIControl beginAnimations:@"hei" context:nil];
    [UIControl setAnimationDuration:0.25];
    
    control.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.25];
    tour.view.alpha=1.0;
    [UIControl commitAnimations];
    
    
    //[tour release];
    
    
    //522,349
    
}

-(void)huoqujiangli{
    
    if (getA!=nil) {
        [getA.view removeFromSuperview];
        [getA release];
        getA=nil;
    }
    getA=[[GetAward alloc]initWithNibName:@"GetAward" bundle:nil];
    getA.view.frame=CGRectMake(250, 170, 522, 271);
    
    
    if (control==nil) 
        control=[[UIControl alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)];
    control.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.0];
    [self.view addSubview:control];
    [control addSubview:getA.view];
    getA.view.alpha=0.0;
    [control addTarget:self action:@selector(removeControl:) forControlEvents:UIControlEventTouchUpInside];
    [UIControl beginAnimations:@"hei" context:nil];
    [UIControl setAnimationDuration:0.2];
    
    control.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.25];
    getA.view.alpha=1.0;
    [UIControl commitAnimations];
    
    
    
}
-(void)bangzhu{
    if (ref!=nil) {
        [ref.view removeFromSuperview];
        [ref release]; 
        ref=nil;
    }
    
    ref=[[Reference alloc]initWithNibName:@"Reference" bundle:nil];
    ref.view.frame=CGRectMake(55, 150, 904, 478);
    if (control==nil) 
        control=[[UIControl alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)];
    control.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.0];
    [self.view addSubview:control];
    [control addSubview:ref.view];
    ref.view.alpha=0.0;
    [control addTarget:self action:@selector(removeControl:) forControlEvents:UIControlEventTouchUpInside];
    [UIControl beginAnimations:@"hei" context:nil];
    [UIControl setAnimationDuration:0.2];
    
    control.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.25];
    ref.view.alpha=1.0;
    [UIControl commitAnimations];
}


-(void)removeControl:(UIControl *)sender{
    
    [UIControl beginAnimations:@"hei" context:nil];
    [UIControl setAnimationDuration:0.2];
    sender.alpha=0.0;
    sender.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.0];
    [UIControl commitAnimations];
    
    [self performSelector:@selector(releaseControl) withObject:nil afterDelay:0.25];
}
-(void)releaseControl{
    
    [control removeFromSuperview];
    [control release];
    control=nil;
}
#pragma mark ---TeachDelegate---
-(void)bottomAppear{
    
    //    if (teach!=nil) {
    //        //[teach.view removeFromSuperview];
    //        [teach release]; 
    teach=nil;
    //    }
    
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationDelegate:self];
    bottomView.transform=CGAffineTransformScale([self transformForOrientation], 1.0, 1.0);
    bottomView.alpha=1.0;
    [UIView commitAnimations];
}


#pragma mark ---TournamentDelegate---
-(void)startTourWithMoneyString:(NSString *)money{
    [self removeControl:control];
    NSLog(@"StartTournament!!");
    
}
#pragma mark ---MenuIpadDelegate---
-(void)login{
    if (loginViewController!=nil) {
        [loginViewController.view removeFromSuperview];
        [loginViewController release];
        loginViewController=nil;
    }
    loginViewController=[[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];
    loginViewController.view.frame=CGRectMake(250, 173, 522, 276);
    if (control==nil) 
        control=[[UIControl alloc]initWithFrame:CGRectMake(0, 0, 1024, 768)];
    control.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.0];
    [self.view addSubview:control];
    [control addSubview:loginViewController.view];
    loginViewController.view.alpha=0.0;
    [control addTarget:self action:@selector(removeControl:) forControlEvents:UIControlEventTouchUpInside];
    [UIControl beginAnimations:@"hei" context:nil];
    [UIControl setAnimationDuration:0.25];
    
    control.backgroundColor=[UIColor colorWithWhite:0.0 alpha:0.25];
    loginViewController.view.alpha=1.0;
    [UIControl commitAnimations];
    
}

@end
